package com.heima.test3;

import java.util.Comparator;
import java.util.TreeSet;

public class Test01 {
    public static void main(String[] args) {
        // - 创建5个Person对象,存到Treeset集合中
        TreeSet<Person> set = new TreeSet<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                if (o1.age > o2.age) {
                    return -1;
                } else if (o1.age < o2.age) {
                    return 1;
                } else {
                    if (o1.weight > o2.weight) {
                        return 1;
                    } else {
                        return -1;
                    }
                }
            }
        });
        set.add(new Person("张三", 18, 163.3));
        set.add(new Person("李四", 10, 63.3));
        set.add(new Person("王五", 18, 180.3));
        set.add(new Person("赵六", 6, 40.3));
        set.add(new Person("李二", 30, 163.3));
        // - 要求使用比较器排序,让集合中的对象按照age从大到小排序,如果age相同,按照weight从小到大排序
        System.out.println(set);

    }
}
